package com.upc.tp.timeplanning.mapper;


import com.upc.tp.timeplanning.entity.Parent;
import com.upc.tp.timeplanning.entity.Task;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface TaskMapper {

    @Select("SELECT * FROM task")
    List<Task> getAll();

    @Select("SELECT * FROM task where username = #{username} ")
    List<Task> getByUsername(@Param("username")String username);

    @Select("SELECT * FROM task where username = #{username} AND parent_pass = 0")
    List<Task> checkByUsername(@Param("username")String username);

    @Select("SELECT * FROM task where username = #{username} AND start_day >= #{start_day} AND end_day <= #{end_day} Order By start_day")
    List<Task> getByDate(@Param("username")String username,@Param("start_day")Date start_day,@Param("end_day")Date end_day);

    @Insert("INSERT INTO task(username,content,creation_time,subject,type,start_time,end_time,start_day,end_day,rule_id,parent_pass,finish,repeat_time) VALUES(#{username},#{content},#{creation_time},#{subject},#{type},#{start_time},#{end_time},#{start_day},#{end_day},#{rule_id},#{parent_pass},#{finish},#{repeat_time})")
    int insert(@Param("username")String username,
               @Param("content")String content,
               @Param("creation_time") Date creation_time,
               @Param("subject")String subject,
               @Param("type")String type,
               @Param("start_time")Integer start_time,
               @Param("end_time")Integer end_time,
               @Param("start_day")Date start_day,
               @Param("end_day")Date end_day,
               @Param("rule_id")Integer rule_id,
               @Param("parent_pass")Integer parent_pass,
               @Param("finish")Integer finish,
               @Param("repeat_time")Integer repeat_time);

    @Update("UPDATE task SET repeat_time = #{repeat_time} WHERE task_id = #{task_id}")
    int updateRepeatTime(@Param("repeat_time")Integer repeat_time,@Param("task_id")Integer task_id);

    @Update("UPDATE task SET parent_pass = 1 WHERE task_id = #{task_id}")
    int passSingle(@Param("task_id")Integer task_id);

    @Update("UPDATE task SET parent_pass = 1 WHERE username = #{username} AND parent_pass = 0 ")
    int passAll(@Param("username")String username);

    @Delete("DELETE FROM task WHERE task_id = #{task_id}")
    int delete(@Param("task_id")Integer task_id);
}
